# set project name
project(logcplus)
set(PROJECT_VERSION "1.0.0")

# set cmake mini version
cmake_minimum_required(VERSION 2.8)

if(CMAKE_VERSION VERSION_GREATER 3)
	cmake_policy(SET CMP0054 NEW)
endif()

# Opthions switch
option(ENABLE_TEST_MODULE   "ENABLE TEST MODULE"   ON  )

# print build info
message(STATUS "CMAKE_SYSTEM_NAME  " ${CMAKE_SYSTEM_NAME})
message(STATUS "PROJECT_SOURCE_DIR " ${PROJECT_SOURCE_DIR})
message(STATUS "PROJECT_BINARY_DIR " ${PROJECT_BINARY_DIR})
message(STATUS "CMAKE_BINARY_DIR   " ${CMAKE_BINARY_DIR})
message(STATUS "C compiler:          ${CMAKE_C_COMPILER}")
message(STATUS "C++ compiler:        ${CMAKE_CXX_COMPILER}")

# set cmake install prefix
set(CMAKE_INSTALL_PREFIX $ENV{HOME})

# set c++11 options
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g ")
add_compile_options(-g -std=c++0x )

# set Build Type (Debug/Release)
if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Debug")
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

# check build type 
if(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
	add_definitions(-D_DEBUG_)
	add_compile_options(-O0)
	if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
		# using regular Clang or AppleClang
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -Wall -Wno-invalid-source-encoding -Wshadow -Wshorten-64-to-32 ")
	elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
		# using GCC
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -Wall -pedantic -Wshadow -Wextra ")
	endif()	
	##set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/Debug)
	message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
elseif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
	add_definitions(-D_RELEASE_)
	add_compile_options(-O3)
	if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
		# using regular Clang or AppleClang
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-value -Wno-invalid-source-encoding -Wno-parentheses ")
	elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
		# using GCC
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-unused-value  -Wno-long-long ")
	endif()		
	set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/Release)
	message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
endif()

# Ensure that all executables and libraries end up in the same directory. Actual
# files might end up in a configuration subdirectory.
if(NOT EXECUTABLE_OUTPUT_PATH)
	set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL
		   "Single output directory for building all executables.")
endif()
if(NOT LIBRARY_OUTPUT_PATH)
	set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL
		   "Single output directory for building all libraries.")
endif()
if(NOT ARCHIVE_OUTPUT_PATH)
	set(ARCHIVE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL
		   "Single output directory for building all archives.")
endif()
if(NOT INCLUDE_OUTPUT_PATH)
	set(INCLUDE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include CACHE INTERNAL
		   "Single output directory for building all includes.")
endif() 

# build CMAKE_INSTALL_PREFIX
if(NOT EXECUTABLE_INSTALL_PATH)
	set(EXECUTABLE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin CACHE INTERNAL
		   "Single install directory for building all executables.")
endif()
if(NOT LIBRARY_INSTALL_PATH)
	set(LIBRARY_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib CACHE INTERNAL
		   "Single install directory for building all libraries.")
endif()
if(NOT ARCHIVE_INSTALL_PATH)
	set(ARCHIVE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin CACHE INTERNAL
		   "Single install directory for building all archives.")
endif()
if(NOT INCLUDE_INSTALL_PATH)
	set(INCLUDE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/include CACHE INTERNAL
		   "Single install directory for building all includes.")
endif() 

# set PERMISSIONS
set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
     OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ )

set(CMAKE_INSTALL_DEFAULT_LIBRARY_PERMISSIONS
	OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ )   

set(CMAKE_INSTALL_DEFAULT_EXECUTABLE_PERMISSIONS
	OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ ) 

# add_subdirectory
add_subdirectory(src)

if(ENABLE_TEST_MODULE) 
add_subdirectory(demo) 
endif()
